<script setup lang="ts">
import { reactive } from 'vue';

const props: any = defineProps<{
    ujt: any;
}>();
const { $fn, $global } = props.ujt;
const updateData: any = {
    rule: {
        uploadzip: { filename: 'updateweb.zip', comp: 'AsaiUpBinary' },
    },
    data: reactive({
        uploadzip: '',
        commond: 'reboot',
    }),
};
function submitUpdate() {
    if (updateData.data.uploadzip && updateData.data.commond) {
        $global.pagebusy = { v: 'update...' };
        $fn.api['webserver']
            .apiGet('/api/asaizip/manage/get/', {
                type: 'unzip',
                clean: 1,
                zipfile: './webdata/upload/updateweb.zip',
                unzipdir: './webdata/upload/updateweb/',
            })
            .then((resunzip: any) => {
                console.log(666.2001, resunzip);
                $fn.api['webserver']
                    .apiGet(
                        '/api/asaijson/manage/select/?path=./websys/update/updateweb/config.json'
                    )
                    .then((resconfig: any) => {
                        console.log(666.2002, resconfig);
                        $fn.api['webserver']
                            .apiPost(
                                '/api/asaifile/manage/copy/',
                                resconfig.data
                            )
                            .then((rescopy: any) => {
                                console.log(666.2003, rescopy);
                            });
                    });
            });
    } else {
        $global.msg.fn({
            type: 'err',
            con: 'Update error!',
        });
    }
}
</script>

<template>
    <h1>Update Web</h1>
    <AsaiForm :ujt="ujt" :asaidata="updateData"></AsaiForm>
    <button class="as-update-btn" @pointerdown="submitUpdate()">
        Update Web
    </button>
</template>
<style scoped lang="scss">
.as-update-btn {
    background-color: var(--cm8);
    color: var(--cm0);
    padding: 0 28px;
    height: 58px;
}
</style>
